<?php
function createTree(&$node, &$nodes, $url, &$id_map) {
	$res = $node->getFields(array('idn', 'title'));
	
	if ($url) $url .= '/';
	$res['url'] = $url.$node->getField('idn');
    
	$ids_str = $node->getField('order');
    $id_map[$res['id']] = $res;
    if ($ids_str) {
		$ids = explode(',', $ids_str);
		
		foreach ($ids as $id) {
			$key = $nodes[$id]->getField('idn');
			$res['nodes'][$key] = createTree($nodes[$id], $nodes, $res['url'], $id_map);
		}
	}

    return $res;
}

?>